/*
 * Copyright 2010 Askar Kalykov, oxygene.core@gmail.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.oxygenecore.processor;

import com.oxygenecore.processor.expression.VariableValue;
import com.oxygenecore.processor.expression.arithmetic.ArithmeticExpression;
import com.oxygenecore.processor.expression.arithmetic.integer.AbstractIntegerArithmeticExpression;
import com.oxygenecore.processor.expression.arithmetic.integer.AddIntegerArithmeticExpression;
import com.oxygenecore.processor.expression.logical.AbstractIntegerCompareExpression;
import com.oxygenecore.processor.expression.logical.ComparisionExpression;
import com.oxygenecore.processor.expression.Constant;
import com.oxygenecore.processor.expression.logical.LessIntegerCompareExpression;
import com.oxygenecore.processor.statement.DeclareVariableStatement;
import com.oxygenecore.processor.statement.ForLoopStatement;
import com.oxygenecore.processor.statement.PrintlnStatement;
import com.oxygenecore.processor.statement.SetVariableValueStatement;
import org.junit.Test;

/**
 * @author Askar Kalykov
 *         Date: 11.09.2010
 *         Time: 16:54:06
 */

public class TestProcessor {


    @Test
    public void testProcessor() throws StatementException, StreamException {
        StatementStreamBuilder builder = new StatementStreamBuilder();
        builder.addStatement(new DeclareVariableStatement(Constant.get("X"), Constant.get(Integer.class), Constant.get(100)));

        builder.addStatement(new ForLoopStatement(
                new DeclareVariableStatement(Constant.get("i"), Constant.get(Integer.class), Constant.get(0)),
                new LessIntegerCompareExpression(new VariableValue<Integer>("i"), Constant.get(5)),
                new PrintlnStatement(new AddIntegerArithmeticExpression(new VariableValue<Integer>("X"), new VariableValue<Integer>("i"))),
                new SetVariableValueStatement("i", new AddIntegerArithmeticExpression(new VariableValue<Integer>("i"), Constant.get(1)))
        ));

//        builder.addStatement(new PrintlnStatement(new VariableValue("X")));

        Configuration configuration = Configuration.getInstance();

        ExecutionContext executionContext = configuration.createExecutionContext(GlobalConstants.GLOBAL_EXECUTION_CONTEXT);

        Processor processor = configuration.createProcessor();
        processor.process(builder.buildStatementStream(), executionContext);

    }

}
